package com.mqqzt.douban;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class MeActivity extends Activity implements OnItemClickListener {
	private ListView mListView;
	private static final String[] arr = {"我读...","我看...","我听...","我评...","我的日记...","我的资料...","小组..."};
	private SharedPreferences sp;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.meactivity);
		sp = getSharedPreferences("config", Context.MODE_PRIVATE);
		mListView = (ListView) this.findViewById(R.id.melistview);
		mListView.setAdapter(new ArrayAdapter<String>(this, R.layout.me_item, R.id.fav_title, arr));
		mListView.setOnItemClickListener(this);
	}
	
	private boolean isUserAuthoroized(){
		String accesstoken = sp.getString("accesstoken", "");
		String tokensecret = sp.getString("tokensecret", "");
		if("".equals(accesstoken) || "".equals(tokensecret)){
			return false;
		}
		return true;
	}

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position,
			long id) {
		if(isUserAuthoroized()){
			//进入到对应界面
			switch (position) {
			case 0:
				Intent myReadIntent = new Intent(MeActivity.this, MyReadActivity.class);
				startActivity(myReadIntent);
				break;
			case 4:
				Intent myNoteIntent = new Intent(MeActivity.this, MyNoteActivity.class);
				startActivity(myNoteIntent);
				break;
			case 5:
				Intent myInfoIntent = new Intent(MeActivity.this, MyInfoActivity.class);
				startActivity(myInfoIntent);
				break;

			default:
				break;
			}
		}else{
			//定向到登录界面
			Intent intent = new Intent(this, LoginActivity.class);
			startActivity(intent);
		}
		
	}
}
